package com.camel.auth.exceptions;

import cn.dev33.satoken.exception.NotLoginException;
import cn.dev33.satoken.sso.exception.SaSsoException;
import cn.dev33.satoken.util.SaResult;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import javax.servlet.http.HttpServletResponse;

/**
 * @author camel
 */
@RestControllerAdvice
public class GlobalExceptionHandler {
    /**
     * 全局异常拦截
     * @param e
     * @return
     */
    @ExceptionHandler
    public void handlerException(NotLoginException e, HttpServletResponse response) {
        response.setStatus(HttpStatus.UNAUTHORIZED.value());
    }

    /**
     * SSO异常拦截
     * @param e
     * @return
     */
    @ExceptionHandler
    public String handlerSsoException(SaSsoException e) {
        String msg = "当前会话没有相关业务地址，请先访问业务地址";
        return msg;
    }
}
